package com.leadbank.baselbf.manager;

import android.content.Context;
import android.content.SharedPreferences;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName: SPLBFManager
 * @Description:
 * @Author: zhouzhiguo
 * @Date: 2022/7/8 11:06
 * @Version: 4.8.7
 * 上海利得金融科技集团版权所有.
 */

public class SPLBFManager {

    /**
     * 存储的位置
     */
    private static  String spName="lbfAndroid";

    private static ConcurrentHashMap<String, SharedPreferences> sCacheMap = new ConcurrentHashMap<>(10);

    public static String getString(Context context,String key){
        SharedPreferences pre= getSP(context,spName);
        return pre.getString(key, null);
    }
    public static boolean setString(Context context,String key, String value){
        SharedPreferences pre= getSP(context,spName);
        return pre.edit().putString(key, value).commit();
    }

    private static final String TAG = SPLBFManager.class.getName();


    public static boolean getBoolean(Context context,String name,String key){
        SharedPreferences pre= getSP(context,name);
        return pre.getBoolean(key, false);
    }
    public static boolean getBoolean(Context context,String key){
        SharedPreferences pre= getSP(context,spName);
        return pre.getBoolean(key, false);
    }
    public static boolean setBoolean(Context context,String key, boolean value){
        SharedPreferences pre= getSP(context,spName);
        return pre.edit().putBoolean(key, value).commit();
    }
    public static boolean  setBoolean(Context context,String name,String key, boolean value){
        SharedPreferences pre= getSP(context,name);
        return pre.edit().putBoolean(key, value).commit();
    }

    public static boolean setString(Context context,String name,String key, String value){
        SharedPreferences pre= getSP(context,name);
        return pre.edit().putString(key, value).commit();
    }


    public static String getString(Context context,String name,String key){
        SharedPreferences pre= getSP(context,name);
        return pre.getString(key, null);
    }
    public static String getString(Context context,String name,String key,String defValue){
        SharedPreferences pre= getSP(context,name);
        return pre.getString(key, defValue);
    }
    public static boolean setInt(Context context,String name,String key, int value){
        SharedPreferences pre= getSP(context,name);
        return pre.edit().putInt(key, value).commit();
    }
    public static boolean setInt(Context context,String key, int value){
        SharedPreferences pre= getSP(context,spName);
        return pre.edit().putInt(key, value).commit();
    }

    public static int getInt(Context context,String name,String key){
        SharedPreferences pre= getSP(context,name);
        return pre.getInt(key, 0);
    }
    public static int getInt(Context context,String key){
        SharedPreferences pre= getSP(context,spName);
        return pre.getInt(key, 0);
    }

    public static boolean removeValue(Context context,String name,String key){
        SharedPreferences pre= getSP(context,name);
        return pre.edit().remove(key).commit();
    }

    private static SharedPreferences getSP(Context context,String name){
        if (sCacheMap.containsKey(name) && sCacheMap.get(name) != null) {
            return sCacheMap.get(name);
        } else {
            SharedPreferences preferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
            sCacheMap.put(name, preferences);
            return preferences;
        }
    }

    public  static Map<String, ?> getAll(Context context){
        SharedPreferences pre= getSP(context,spName);
        return pre.getAll();
    }


}
